/********************************************************************************
 * Copyright (c)2016-2020, ShenZhen WanJiaAn Technology CO.,LTD.
 * All Rights Reserved.
 *
 * File Name     : ProductManager.c
 * Author        : joki.zhu
 * Date          : 2019-10-15
 *
 * Record        :
 * 1.Date        : 2019-10-15
 *   Author      : joki.zhu
 *   Modification: Created file
 ********************************************************************************/
#include "ProductManager.h"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

PRODUCT_HANDLE_S gProductHandleMap [PRODUCT_MODEL_LAST] = 
{
    {
        .ProductModel =         PRODUCT_MODEL_B1,
        .Client =               PRODUCT_CLIENET_CN,
        .Chip =                 PRODUCT_CHIP_HI3518EV300,
        .Sensor =               PRODUCT_SENSOR_PS5260,
        .SensorImageWidth =     1920,
        .SensorImageHeigh =     1080,
        .Wifi =                 PRODUCT_WIFI_HI1131S,
        .HardWareVersion =      "B1-MAIN-V10",
        .GpioMap =              {-1,38,-1,36,-1,-1,-1,32,-1,-1,37,160},
        .GpioTriggerLevelMap =  {-1, 1,-1,1,-1,-1,-1, 1,-1,-1, 1,  0},
        .bAdcPhotoresistance =  1,
        .AdcMaxValue =          70,
        .AdcMinValue =          10,

        .bLAN =                 0,
        .b4G =                  0,
        .bMotor =               0,
        .bUVC =                 0,
        .bInitImageflip =       0,
        .bAudio =               1,
        .bOsdshow =             1, 
    },

    {
        .ProductModel =         PRODUCT_MODEL_B5,
        .Client =               PRODUCT_CLIENET_CN,
        .Chip =                 PRODUCT_CHIP_HI3518EV300,
        .Sensor =               PRODUCT_SENSOR_JXF37,
        .SensorImageWidth =     1920,
        .SensorImageHeigh =     1080,
        .Wifi =                 PRODUCT_WIFI_HI3861L,
        .HardWareVersion =      "B5-MAIN-V10",
        .GpioMap =              {-1,38,37,36,199,-1,-1,32,-1,-1,37,262},
        .GpioTriggerLevelMap =  {-1, 1, 1, 1, 1,-1,-1, 1,-1,-1, 1,  0},
        .bAdcPhotoresistance =  1,
        .AdcMaxValue =          100,
        .AdcMinValue =          20,
    
        .bLAN =                 0,
        .b4G =                  0,
        .bMotor =               0,
        .bUVC =                 0,
        .bInitImageflip =       0,
        .bAudio =               1,
        .bOsdshow =             1, 
    },
    {
        .ProductModel =         PRODUCT_MODEL_LAST,
        .Client =               PRODUCT_CLIENET_CN,
        .Chip =                 PRODUCT_CHIP_NUM,
        .Sensor =               PRODUCT_SENSOR_NUM,
        .SensorImageWidth =     1280,
        .SensorImageHeigh =     720,
        .Wifi =                 PRODUCT_WIFI_NUM,
        .HardWareVersion =      "HwV1.0.0_1",
        .GpioMap =              {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
        .GpioTriggerLevelMap =  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
        .bAdcPhotoresistance =  0,
        .AdcMaxValue =          0,
        .AdcMinValue =          0,
        .bLAN =                 0,
        .b4G =                  0,
        .bMotor =               0,
        .bUVC =                 0,
        .bInitImageflip =       0,
        .bAudio =               0,
        .bOsdshow =             1, 
    }
};

static PRODUCT_HANDLE_S *gProductHandleUse=NULL;

int ProductInit(void)
{
    int ProductModel = PRODUCT_MODEL_B5;
    
    gProductHandleUse = &gProductHandleMap[ProductModel];

    return 0;
}

PRODUCT_HANDLE_S *ProductGetHandle()
{
    if(NULL == gProductHandleUse){
        printf("gProductHandleUse is null\n");
        exit(0);
    }
    return gProductHandleUse;
}

int ProductGpioConvert(PRODUCT_GPIO_TYPE_E _Gpio)
{
    if (_Gpio < PRODUCT_GPIO_PHOTORESISTANCE || _Gpio >= PRODUCT_GPIO_LAST){
        return -1;
    }
    return gProductHandleUse->GpioMap[_Gpio];
}


char ProductGpioTriggerConvert(PRODUCT_GPIO_TYPE_E _Gpio)
{
    if (_Gpio < PRODUCT_GPIO_PHOTORESISTANCE || _Gpio >= PRODUCT_GPIO_LAST){
        return -1;
    }
    return gProductHandleUse->GpioTriggerLevelMap[_Gpio];
}

